<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019/11/12
 * Time: 13:33
 */

namespace app\common\service;


class NormalRule
{
    /**
     * @name 列表
     * @param $host_id
     * @param $group_id
     * @param $params
     * @param $limit
     * @return array
     * @author wx
     * @date 2019/11/12 14:11
     */
    function list($host_id, $group_id, $params, $limit)
    {
        $db = db('ips_normal_rule')->alias('nr')
            ->join('host_normal_rule_relation hnrr','nr.id = hnrr.rule_id')
            ->where('hnrr.group_id',$group_id)
            ->where('host_id', $host_id);

        if(isset($params['description']) && !empty($params['description'])){
            $db->where('nr.description', 'like', '%'.$params['description'].'%');
        }
        if(isset($params['status']) && is_numeric($params['status'])){
            $db->where('hnrr.status', $params['status']);
        }
        if(isset($params['handle']) && is_numeric($params['handle'])){
            $db->where('hnrr.handle', $params['handle']);
        }

        $list = $db->field('hnrr.id, nr.description, hnrr.status, hnrr.handle')->paginate($limit)->toArray();

        return $list;
    }
}